package com.fy.service.impl;

import com.fy.mapper.MainMapper;
import com.fy.pojo.*;
import com.fy.service.MainService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class MainServiceImpl implements MainService {
    @Autowired
    MainMapper mainMapper;

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Main> list(Main main, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Main> list = mainMapper.list(main);
        PageInfo<Main> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    @Transactional(readOnly = true)
    public List<Built> getBuilt() {
        return mainMapper.getBuilt();
    }

    @Override
    @Transactional(readOnly = true)
    public List<Type> getType() {
        return mainMapper.getType();
    }

    @Override
    @Transactional(readOnly = true)
    public List<Ground> getGround() {
        return mainMapper.getGround();
    }

    @Override
    public int addMain(Main main) {
        int i = mainMapper.addMain(main);
        List<Prices> pricesList = main.getPricesList();
        for (Prices prices : pricesList) {
            if(prices.getStartTime()==null||prices.getStartTime().equals("")){
                continue;
            }
        }
        mainMapper.addPrices(pricesList,main.getSid());
        return i;
    }

    @Override
    public List<Main> count() {
        return mainMapper.count();
    }
}
